<style lang="scss" scoped>
.order-list {
  padding: 0 0.2rem;

  .order-box {
    background-color: #ffffff;
    margin: 0.3rem 0;

    .content {
      display: flex;
      padding: 0.3rem;
      border-bottom: 1px solid #eeeeee;

      .img-box {
        display: flex;
        flex-basis: 30%;
      }

      .detail-box {
        display: flex;
        flex-basis: 70%;
        flex-direction: column;
        padding: 0 0.2rem;

        .title {
          font-size: 0.34rem;
          padding-bottom: 0.2rem;
          font-weight: 600;
        }

        .text {
          padding-bottom: 0.1rem;
        }
      }
    }

    .info-box {
      display: flex;
      flex-basis: 100%;
      flex-wrap: wrap;
      padding: 0.3rem;
      font-size: 0.3rem;

      .left {
        display: flex;
        flex-basis: 50%;
        align-items: center;
        justify-content: flex-start;
        padding: 0.1rem 0;
      }

      .right {
        display: flex;
        flex-basis: 50%;
        align-items: center;
        justify-content: flex-end;
        padding: 0.1rem 0;
      }

      .status {
        display: flex;
        flex-basis: 100%;
        align-items: center;
        justify-content: flex-start;
        padding-top: 0.2rem;
      }
    }
  }
}
</style>

<template>
  <div class="order-list">
    <template v-for="item in list">
      
      <!-- 未接订单 -->
      <div v-if="type == 'unreceived'" class="order-box" @click="linkto(item)">
        <div class="content">
          <div class="img-box">
            <van-image width="100%" height="2rem" fit="cover" :src="fileUrl+item.packageImg" />
          </div>
          <div class="detail-box">
            <p class="title">{{item.packageName}}</p>
            <p class="text">就诊医院：{{item.hospitalName}}</p>
            <p class="text">就诊科室：{{item.departmentName}}</p>
            <p class="text">就诊时间：{{item.serviceDate}}</p>
          </div>
        </div>
        <div class="info-box">
          <div class="left">
            收入：<span class="num">{{item.income}}</span>
          </div>
          <div class="right" @click="linkto(item)">查看详情</div>
        </div>
      </div>

      <!-- 进行中、已完成或已取消的 -->
      <div v-else class="order-box" @click="linkto(item)">
        <div class="content">
          <div class="img-box">
            <van-image width="100%" height="1.5rem" fit="cover" :src="fileUrl+item.packageImg" />
          </div>
          <div class="detail-box">
            <p class="title">就诊人：{{item.membersName}}</p>
            <p class="text">订单号：{{item.ordernum}}</p>
            <p class="text">服务时间：{{item.serviceDate}}</p>
          </div>
        </div>
        <div class="info-box">
          <div class="left">
            服务套餐：{{item.packageName}}
          </div>
          <div class="right">
            收入：<span class="num">{{item.income}}</span>
          </div>
          <div class="left">{{item.serviceTrackDate}}</div>
          <div class="right">{{item.trackStatusStr}}</div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import { fileUrl } from '../api/index';
import { trunc } from '../utils/index';

export default {
  name: 'OrderList',
  props: {
    type: {
      type: String,
      required: true,
      default: 'unreceived'
    },
    list: {
      type: Array,
      required: true,
      default: []
    }
  },
  data() {
    return {
      fileUrl
    };
  },
  watch: {
    list: {
      handler(data) {
        if (this.type === 'unreceived') {
          data.forEach(el => {
            el.hospitalName = trunc(el.hospitalName, 8, '..');
          });
        }
      },
      immediate: true
    }
  },
  methods: {
    linkto({ id }) {
      this.$router.push({
        path: '/order/detail',
        query: {
          id
        }
      });
    }
  }
};
</script>